<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="" >
        <p>
            <label for="">用户：</label>
            <input type="text" name="username" id="user">
        </p>
        <p>
            <label for="">密码：</label>
            <input type="text" name="pass" id="pwrod">
        </p>
        <button>登录</button>
    </form>
    <script>
        var form = document.querySelector('form');
        var user = document.querySelector('#user');
        var pwrod = document.querySelector('#pwrod');
        form.onsubmit = function () {
            let e = window.event;
            // 阻止默认表单提交的时候刷新浏览器的行为
            e.returnValue = false;
            // 初始化XMLHttpRequest
            let ajax = new XMLHttpRequest();

            // 请求方式为GET时,在请求地址后面直接拼接 ？key1=value1&key2=value2
            ajax.open('get', `../2.2denglu.php?username=${user.value}&pass=${pwrod.value}`);
            // 发送请求
            ajax.send();

            ajax.onload=function(){
                console.log(ajax.responseText);
            }
        }
    </script>
</body>

</html>